<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    :okButtonProps="{ props: {disabled: disableSubmit} }"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订阅名称">
          <a-input placeholder="请输入订阅名称" v-decorator="['fdName', validatorRules.fdName ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订阅说明">
          <a-input placeholder="请输入订阅说明" v-decorator="['fdExpain', validatorRules.fdExpain ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="是否脱敏">
          <j-dict-select-tag placeholder="请输入是否脱敏"  v-decorator="['fdDes',validatorRules.fdDes  ]" :triggerChange="true" dictCode="autossc_release" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="应用工程">
          <j-dict-select-tag  v-decorator="['fdProject', validatorRules.fdProject]" placeholder="请输入应用工程" dictCode="t_sys_project,fd_projName,fd_projid," :triggerChange="true"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="创建时间">
          <a-date-picker showTime format='YYYY-MM-DD HH:mm:ss' v-decorator="[ 'createTime', validatorRules.createTime ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="开始日期">
          <a-date-picker showTime format='YYYY-MM-DD' v-decorator="[ 'fdRunDate', validatorRules.fdRunDate ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="结束日期">
          <a-date-picker showTime format='YYYY-MM-DD' v-decorator="[ 'fdRunEndDate', {} ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="脱敏目标库">
          <j-select-multiple  v-decorator="['fdSource', validatorRules.fdSource]"  :options="jselectMultiple.options " :triggerChange="true"  />

        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="状态">
          <j-dict-select-tag placeholder="请输入状态"  v-decorator="['fdStatus',validatorRules.fdStatus]" :triggerChange="true" dictCode="operssc_status"  />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="申请人">
          <!-- <a-input placeholder="请输入申请人" v-decorator="['fdApplyUser', {} ]" />-->
          <j-dict-select-tag  v-decorator="['fdApplyUser', {}]"  dictCode="sys_user,username,id," />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="复核人">
          <j-dict-select-tag  v-decorator="['fdCheckUser2', {}]"  dictCode="sys_user,username,id," />
        </a-form-item>


      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"
  import JSelectMultiple from '@/components/jeecg/JSelectMultiple'

  export default {
    name: "OpersscArModal",
    components: {
      JSelectMultiple
    },
    data () {
      return {
        jselectMultiple: {
          options: [
            { text: 'UAT', value: 'UAT' },
            { text: 'SIT', value: 'SIT' },
            { text: 'Develop', value: 'Develop' }

          ],
          value: 'UAT'
        },
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        fdName:{rules: [{ required: true, message: '请输入订阅名称!' }]},
        fdExpain:{rules: [{ required: true, message: '请输入订阅说明!' }]},
        fdDes:{rules: [{ required: true, message: '请输入是否脱敏!' }]},
        fdProject:{rules: [{ required: true, message: '请输入应用工程!' }]},
        fdRunDate:{rules: [{ required: true, message: '请输入开始日期!' }]},
          fdRunEndDate:{rules: [{ required: true, message: '请输入日期!' }]},
          createTime:{rules: [{ required: true, message: '请输入日期!' }]},
        fdProNum:{rules: [{ required: true, message: '请输入推送频次!' }]},
        fdSource:{rules: [{ required: true, message: '请输入脱敏目标库!' }]},
        fdApplyUser:{rules: [{ required: true, message: '请输入申请人!' }]},
        fdApplyTime:{rules: [{ required: true, message: '请输入申请时间!' }]},
        fdApplyCast:{rules: [{ required: true, message: '请输入申请描述!' }]},
        fdCheckUser2:{rules: [{ required: true, message: '请输入复合人!' }]},
        fdCheckTime2:{rules: [{ required: true, message: '请输入复合时间!' }]},
        fdCheckCast2:{rules: [{ required: true, message: '请输入复合描述!' }]},
        fdStatus:{rules: [{ required: true, message: '请输入状态!' }]},
        fdRelease:{rules: [{ required: true, message: '请输入是否发布到调度平台!' }]},
        createUser:{rules: [{ required: true, message: '请输入创建人!' }]},
        updateUser:{rules: [{ required: true, message: '请输入修改人!' }]},
        isDelete:{rules: [{ required: true, message: '请输入是否删除!' }]},
        },
        url: {
          add: "/rule/opersscAr/add",
          edit: "/rule/opersscAr/edit",
        },
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'fdName','fdExpain','fdDes','fdProject','fdProNum','fdSource','fdApplyUser','fdApplyCast','fdCheckUser2','fdCheckCast2','fdStatus','fdRelease','createUser','updateUser','isDelete'))
		  //时间格式化
          this.form.setFieldsValue({fdRunDate:this.model.fdRunDate?moment(this.model.fdRunDate):null})
          this.form.setFieldsValue({fdRunEndDate:this.model.fdRunEndDate?moment(this.model.fdRunEndDate):null})
          this.form.setFieldsValue({fdApplyTime:this.model.fdApplyTime?moment(this.model.fdApplyTime):null})
          this.form.setFieldsValue({fdCheckTime2:this.model.fdCheckTime2?moment(this.model.fdCheckTime2):null})
          this.form.setFieldsValue({createTime:this.model.createTime?moment(this.model.createTime):null})
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            formData.fdRunDate = formData.fdRunDate?formData.fdRunDate.format('YYYY-MM-DD HH:mm:ss'):null;
            formData.fdApplyTime = formData.fdApplyTime?formData.fdApplyTime.format('YYYY-MM-DD HH:mm:ss'):null;
            formData.fdCheckTime2 = formData.fdCheckTime2?formData.fdCheckTime2.format('YYYY-MM-DD HH:mm:ss'):null;
            
            console.log(formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>